package com.vict.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;

public class StrUtil {
    public static String getSubStr(String str, String cutStr, int index){
        return str.split(cutStr)[index];
    }

    public static boolean isNullOrEmpty(String str){
        if(str == null){
            return true;
        }else{
            if("".equals(str)){
                return true;
            }else{
                return false;
            }
        }
    }

    public static String getRandomString(int length){
        String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<length;i++){
            int number=random.nextInt(62);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }

    public static String getRandomStringLower(int length){
        String str="abcdefghijklmnopqrstuvwxyz0123456789";
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<length;i++){
            int number=random.nextInt(36);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }

    public static String idCreat(){
        return getRandomString(32);
    }

    public static String toString(List<String> s){
        String res = "";
        if(s == null || s.size() == 0){
            return res;
        }else{
            for(String item : s){
                res += s;
            }
        }
        return res;
    }

    public static String log(List<String> list){
        String ss = "";
        for(String s : Optional.ofNullable(list).orElse(new ArrayList<String>())){
            ss += s;
            ss += ",";
        }
        return ss;
    }

}
